﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using weikebuluo.DAL;
using weikebuluo.Common;
using weikebuluo.Model;

namespace weikebuluo.web.admin.coupon
{
    public partial class couponadd : weikeweixin.web.admin.cs.adminbase
    {
        v_coupon_dal coupondal = new v_coupon_dal();
        protected v_coupon_model couponmodel = new v_coupon_model();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                couponmodel = coupondal.GetModel(int.Parse(Request.QueryString["id"]));//绑定
            }
            switch (Request.Form["action"])
            {
                case "add":
                    add();
                    break;
            }
        }
        //新增
        private void add()
        {
            if (!string.IsNullOrEmpty(Request.Form["id"]))
            {
                couponmodel = coupondal.GetModel(int.Parse(Request.Form["id"]));
            }
            couponmodel.coupon_name = Request.Form["coupon_name"].Trim().ToString();
            couponmodel.coupon_price = Request.Form["coupon_price"].Trim().ToString();
            couponmodel.couponlog_id = int.Parse(Request.Form["couponlog_id"].Trim().ToString());
            string[] NTime = Request.Form["time"].Split('-');
            couponmodel.coupon_stime = DateTime.Parse(NTime[0].Trim());
            couponmodel.coupon_etime = DateTime.Parse(NTime[1].Trim());
            couponmodel.coupon_view = Request.Form["coupon_view"].Trim().ToString();
            couponmodel.user_id = int.Parse(user_id);
            if (!string.IsNullOrEmpty(Request.Form["id"]))
            {
                bool re = coupondal.Update(couponmodel);
                if (re)
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存成功！\",\"url\":\"coupanlist.aspx\",\"error\":\"\"}");
                }
                else
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存失败！\",\"url\":\"couponadd.aspx\",\"error\":\"\"}");
                }
                Response.End();
            }
            else
            {
                int re = coupondal.Add(couponmodel);
                if (re > 0)
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存成功！\",\"url\":\"coupanlist.aspx\",\"error\":\"\"}");
                }
                else
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存失败！\",\"url\":\"couponadd.aspx\",\"error\":\"\"}");
                }

                Response.End();
            }
        }

    }

}